// CLIENT SIDE

function tdm_menu(data)
PlayerName = data:ReadString()
/*
local TestPanel = 0
if TestingPanel != nil then
if TestingPanel:IsVisible( ) then
MsgN('IsVisible')
else
MsgN('IsNotVisible')
end

else
*/
local GAMEMODE_VERSION = "1.3b"

// Start of Main Frame
local MainMenuFrame = vgui.Create( "DFrame" )
MainMenuFrame:SetSize( 600, 250 )
MainMenuFrame:SetTitle("Team Deathmatch Menu: Version "..GAMEMODE_VERSION )
MainMenuFrame:Center()
MainMenuFrame:ShowCloseButton(false)
MainMenuFrame:SetVisible( true )
MainMenuFrame:SetDraggable( false )
MainMenuFrame:MakePopup()
function MainMenuFrame:Paint( w, h )
	draw.RoundedBox( 0, 0, 0, w, h, Color(team.GetColor(LocalPlayer():Team()).r,team.GetColor(LocalPlayer():Team()).g,team.GetColor(LocalPlayer():Team()).b,50))
	surface.SetDrawColor(0,0,0)
	surface.DrawOutlinedRect(1,1,w-1,h-1)
end

/*
if LocalPlayer():GetPData("TDMMenuOpen") == 1 || LocalPlayer():GetPData("TDMMenuOpen") == "1" then
	LocalPlayer():SetPData("TDMMenuOpen", 0)
	MainMenuFrame:Close()
	MsgN('Should be closing')
	return 
end
LocalPlayer():SetPData("TDMMenuOpen", 1)
*/

local CloseButton = vgui.Create( "DButton", MainMenuFrame )
	CloseButton:SetSize( 30, 18 )
	CloseButton:SetPos( 565, 4 )
	CloseButton:SetText( "Close" )
	CloseButton.DoClick = function( btn )
	LocalPlayer():SetPData("TDMMenuOpen", 0)
	MainMenuFrame:Close()
end

/*
local TestingPanel = vgui.Create( "DPanel", MainMenuFrame )
TestingPanel:SetPos( 25, 50 )
TestingPanel:SetSize( 250, 250 )
TestingPanel.Paint = function() -- Paint function
    --Set our rect color below us; we do this so you can see items added to this panel
    surface.SetDrawColor( 50, 50, 50, 255 ) 
    surface.DrawRect( 0, 0, TestingPanel:GetWide(), TestingPanel:GetTall() ) -- Draw the rect
end
*/

// Start of TabsList
local MainMenuSheet = vgui.Create( "DPropertySheet", MainMenuFrame )
MainMenuSheet:SetPos( 5, 27 )
MainMenuSheet:SetSize( 590, 217 )
 
local TabOne = vgui.Create( "DPanelList" )
TabOne:SetPos( 0, 0 )
TabOne:SetSize( MainMenuSheet:GetWide(), MainMenuSheet:GetTall() )
TabOne:SetSpacing( 5 )
TabOne:EnableHorizontal( false )
TabOne:EnableVerticalScrollbar( true )

local TabThree = vgui.Create( "DPanelList" )
TabThree:SetPos( 0, 0 )
TabThree:SetSize( MainMenuSheet:GetWide(), MainMenuSheet:GetTall() )
TabThree:SetSpacing( 5 )
TabThree:EnableHorizontal( false )
TabThree:EnableVerticalScrollbar( true )

local TabTwo = vgui.Create( "DPanelList" )
TabTwo:SetPos( 0, 0 )
TabTwo:SetSize( MainMenuSheet:GetWide(), MainMenuSheet:GetTall() )
TabTwo:SetSpacing( 5 )
TabTwo:EnableHorizontal( false )
TabTwo:EnableVerticalScrollbar( true )
// End of TabList


// Start of Team Tab
local ChooseATeam = vgui.Create("DLabel", TabOne)
ChooseATeam:SetPos(10,5)
ChooseATeam:SetColor( Color( 0, 0, 0, 255 ) )
ChooseATeam:SetFont("default")
ChooseATeam:SetText("Choose a Team:")
ChooseATeam:SizeToContents()

local PlayerTeamList = vgui.Create("DListView", TabOne)
PlayerTeamList:SetPos(273, 0)
PlayerTeamList:SetSize(300, 180)
PlayerTeamList:SetMultiSelect(false)
PlayerTeamList:AddColumn("Player")
PlayerTeamList:AddColumn("Team")
PlayerTeamList:AddColumn("Kills")
PlayerTeamList:AddColumn("Deaths")
for k,v in pairs(player.GetAll()) do
    PlayerTeamList:AddLine(v:Nick(),team.GetName(v:Team()),v:Frags(),v:Deaths())
end

local MenuButton = vgui.Create("DButton", TabOne)
MenuButton:SetText( "Team Chooser:" )
MenuButton:SetPos(7, 20)
MenuButton:SetSize( 150, 25 )
MenuButton.DoClick = function ( btn )
    local MenuButtonOptions = DermaMenu()
	for k,v in pairs(team.GetAllTeams()) do
	if k != 0 and k < 1000 then
		MenuButtonOptions:AddOption(team.GetName(k), function()  
		RunConsoleCommand( "SwitchTDMTeamIndex", tonumber(k) )
		MainMenuFrame:Close()
		end )		
		MenuButtonOptions:Open()
	end
	end	
	
end
// End of Team Tab


// Start of Config Tab
local FriendlyFire = vgui.Create("DLabel", TabTwo)
FriendlyFire:SetPos(10,5)
FriendlyFire:SetColor( Color( 0, 0, 0, 255 ) )
FriendlyFire:SetFont("default")
FriendlyFire:SetText("Friendly Fire")
FriendlyFire:SizeToContents()

local FriendlyFireButton = vgui.Create( "DButton", TabTwo )
	FriendlyFireButton:SetSize( 150, 25 )
	FriendlyFireButton:SetPos( 7, 20 )
	FriendlyFireButton:SetText( "Friendly Fire" )
	FriendlyFireButton.DoClick = function( btn )
    local MenuButtonOptions = DermaMenu()
		MenuButtonOptions:AddOption("Friendly Fire On", function()  
			RunConsoleCommand( "TDMFriendlyFireButton", 1 )
		end )
		MenuButtonOptions:AddOption("Friendly Fire Off", function()  
			RunConsoleCommand( "TDMFriendlyFireButton", 0 )
		end )
	MenuButtonOptions:Open()
end

local TDM_CONSOLE_HELP = vgui.Create("DLabel", TabTwo)
TDM_CONSOLE_HELP:SetPos(225,5)
TDM_CONSOLE_HELP:SetColor( Color( 0, 0, 0, 255 ) )
TDM_CONSOLE_HELP:SetFont("default")
TDM_CONSOLE_HELP:SetText("TDM HELP")
TDM_CONSOLE_HELP:SizeToContents()

local TDM_CONSOLE_HELP_BUTTON = vgui.Create( "DButton", TabTwo )
	TDM_CONSOLE_HELP_BUTTON:SetSize( 150, 25 )
	TDM_CONSOLE_HELP_BUTTON:SetPos( 175, 20 )
	TDM_CONSOLE_HELP_BUTTON:SetText( "TDM HELP" )
	TDM_CONSOLE_HELP_BUTTON.DoClick = function( btn )
    RunConsoleCommand( "tdm_help" )
    RunConsoleCommand( "tdm_help_message" )
end

local CountDownTimer = vgui.Create("DLabel", TabTwo)
CountDownTimer:SetPos(205,55)
CountDownTimer:SetColor( Color( 0, 0, 0, 255 ) )
CountDownTimer:SetFont("default")
CountDownTimer:SetText("Countdown Timer")
CountDownTimer:SizeToContents()

local CountDownTimerButton = vgui.Create( "DButton", TabTwo )
	CountDownTimerButton:SetSize( 150, 25 )
	CountDownTimerButton:SetPos( 175, 70 )
	CountDownTimerButton:SetText( "Countdown Timer" )
	CountDownTimerButton.DoClick = function( btn )
    local MenuButtonOptions = DermaMenu()
		MenuButtonOptions:AddOption("Timer On", function()  
			RunConsoleCommand( "TDMTimerOn", 1 )
		end )
		MenuButtonOptions:AddOption("Timer Off", function()  
			RunConsoleCommand( "TDMTimerOn", 0 )
		end )
	MenuButtonOptions:Open()
end


local CountDownTimerText = vgui.Create("DLabel", TabTwo)
CountDownTimerText:SetPos(178,105)
CountDownTimerText:SetColor( Color( 0, 0, 0, 255 ) )
CountDownTimerText:SetFont("default")
CountDownTimerText:SetText("Timer Count Down (Number)")
CountDownTimerText:SizeToContents()

local GoalDermaBoxEntry = vgui.Create( "DTextEntry", TabTwo)
GoalDermaBoxEntry:SetPos( 175,120 )
GoalDermaBoxEntry:SetTall( 25 )
GoalDermaBoxEntry:SetWide( 75 )
GoalDermaBoxEntry:SetEnterAllowed( true )
GetSetHourNow = 0
for k,v in pairs(player.GetAll()) do
    GetSetHourNow = v:GetPData("MyTimerLimiter")
end
GoalDermaBoxEntry:SetValue(GetSetHourNow)
GoalDermaBoxEntry.OnEnter = function()
    RunConsoleCommand( "TDMCustomCountDownTimer", GoalDermaBoxEntry:GetValue() )
end

local CountDownTimerButton = vgui.Create( "DButton", TabTwo )
	CountDownTimerButton:SetSize( 72, 25 )
	CountDownTimerButton:SetPos( 253, 120 )
	CountDownTimerButton:SetText( "Set Timer" )
	CountDownTimerButton.DoClick = function( btn )
    RunConsoleCommand( "TDMCustomCountDownTimer", GoalDermaBoxEntry:GetValue() )
end


local CustomGoalText = vgui.Create("DLabel", TabTwo)
CustomGoalText:SetPos(10,55)
CustomGoalText:SetColor( Color( 0, 0, 0, 255 ) )
CustomGoalText:SetFont("default")
CustomGoalText:SetText("Goal Score Limit (Number)")
CustomGoalText:SizeToContents()

local GoalDermaBox = vgui.Create( "DTextEntry", TabTwo)
GoalDermaBox:SetPos( 7,70 )
GoalDermaBox:SetTall( 25 )
GoalDermaBox:SetWide( 75 )
GoalDermaBox:SetEnterAllowed( true )
CurScoreMM = 0
for k,v in pairs(player.GetAll()) do
CurScoreMM = v:GetPData('TDM_Total_Score_Ok')
end
GoalDermaBox:SetValue(CurScoreMM)
GoalDermaBox.OnEnter = function()
    RunConsoleCommand( "TDMCustomGoalLimiter", GoalDermaBox:GetValue() )
end

local GoalButton = vgui.Create( "DButton", TabTwo )
	GoalButton:SetSize( 72, 25 )
	GoalButton:SetPos( 85, 70 )
	GoalButton:SetText( "Set Goal" )
	GoalButton.DoClick = function( btn )
    RunConsoleCommand( "TDMCustomGoalLimiter", GoalDermaBox:GetValue() )
end


local Armor = vgui.Create("DLabel", TabTwo)
Armor:SetPos(10,105)
Armor:SetColor( Color( 0, 0, 0, 255 ) )
Armor:SetFont("default")
Armor:SetText("Armor")
Armor:SizeToContents()

local ArmorButton = vgui.Create( "DButton", TabTwo )
	ArmorButton:SetSize( 150, 25 )
	ArmorButton:SetPos( 7, 120 )
	ArmorButton:SetText( "Armor" )
	ArmorButton.DoClick = function( btn )
    local MenuButtonOptions = DermaMenu()
		MenuButtonOptions:AddOption("Armor On", function()  
			RunConsoleCommand( "TDMArmorButton", 1 )
		end )
		MenuButtonOptions:AddOption("Armor Off", function()  
			RunConsoleCommand( "TDMArmorButton", 0 )
		end )
	MenuButtonOptions:Open()
end
// End of Config Tab


// Start of Weapon Shop
local DisplayHeader = vgui.Create("DLabel", TabThree)
DisplayHeader:SetPos(10,5)
DisplayHeader:SetColor( Color( 0, 0, 0, 255 ) )
DisplayHeader:SetFont("default")
DisplayHeader:SetText("Greetings, ")
DisplayHeader:SizeToContents()

local DisplayName = vgui.Create("DLabel", TabThree)
DisplayName:SetPos(65,5)
DisplayName:SetColor( Color( 0, 0, 0, 255 ) )
DisplayName:SetFont("default")
DisplayName:SetText(PlayerName)
DisplayName:SizeToContents()

local DisplayerWarning = vgui.Create("DLabel", TabThree)
DisplayerWarning:SetPos(10,15)
DisplayerWarning:SetColor( Color( 255, 0, 0, 255 ) )
DisplayerWarning:SetFont("default")
DisplayerWarning:SetText("This Gunshop menu is a beta of this gamemode. So you may experience errors while using this.")
DisplayerWarning:SizeToContents()

local MenuButton = vgui.Create("DButton", TabThree)
MenuButton:SetText( "Weapons:" )
MenuButton:SetPos(10, 30)
MenuButton:SetSize( 150, 25 )
MenuButton.DoClick = function ( btn )
local MenuButtonOptions = DermaMenu()
	for k,v in pairs(Weapons) do
	local ov = string.Explode(":", v)
	local nv = string.upper(v)
	local nv = string.gsub(nv,"WEAPON","")
	local nv = string.gsub(nv,"CS","")
	local nv = string.gsub(nv,"_","")
	local nv = string.Explode(":", nv)
		MenuButtonOptions:AddOption(nv[1]..' - Cost: $'..nv[2], function()  
			RunConsoleCommand( "BuyWeaponIndex", ov[1], ov[2], nv[1] )
			MainMenuFrame:Close()
		end )		
	MenuButtonOptions:Open()
	end	
end

-- Please don't touch below, also line breakers

GetGiveMoneyPlayers = vgui.Create("DListView", TabThree )
GetGiveMoneyPlayers:SetPos(273, 75)
GetGiveMoneyPlayers:SetSize(300, 175)
GetGiveMoneyPlayers:SetMultiSelect(false)
GetGiveMoneyPlayers:AddColumn("Name")
GetGiveMoneyPlayers:AddColumn("Points")
for k,v in pairs(player.GetAll()) do
    GetGiveMoneyPlayers:AddLine(v:Nick(),v:GetPData('MyXPPoints'))
end

GiveMoneyBox = vgui.Create( "DTextEntry", TabThree)
GiveMoneyBox:SetPos( 426,50 )
GiveMoneyBox:SetTall( 25 )
GiveMoneyBox:SetWide( 75 )
GiveMoneyBox:SetEnterAllowed( true )
GiveMoneyBox:SetValue(100)

MoneyButton2 = vgui.Create( "DButton", TabThree )
	MoneyButton2:SetSize( 72, 25 )
	MoneyButton2:SetPos( 350, 50 )
	MoneyButton2:SetText( "Set Point" )
	MoneyButton2.DoClick = function()
	if GetGiveMoneyPlayers:GetLine(GetGiveMoneyPlayers:GetSelectedLine()) == nil then
	else
	RunConsoleCommand( "TDMSetMoney", GetGiveMoneyPlayers:GetLine(GetGiveMoneyPlayers:GetSelectedLine()):GetValue(1), GiveMoneyBox:GetValue() )
	end
end

MoneyButton = vgui.Create( "DButton", TabThree )
	MoneyButton:SetSize( 72, 25 )
	MoneyButton:SetPos( 273, 50 )
	MoneyButton:SetText( "Give Points" )
	MoneyButton.DoClick = function()
	if GetGiveMoneyPlayers:GetLine(GetGiveMoneyPlayers:GetSelectedLine()) == nil then
	else
	RunConsoleCommand( "TDMGiveMoney", GetGiveMoneyPlayers:GetLine(GetGiveMoneyPlayers:GetSelectedLine()):GetValue(1), GiveMoneyBox:GetValue() )
	end
end

// End of Weapon Shop


// Start of TabListName
MainMenuSheet:AddSheet( "Team", TabOne, "icon16/group.png", false, false, "Select a team to be on." )
MainMenuSheet:AddSheet( "Weapon Shop", TabThree, "icon16/wand.png", false, false, "Weapon Shop - Beta" )
--MainMenuSheet:AddSheet( "Leaderboards", TabFour, "icon16/vcard.png", false, false, "Server Leaderboards" )
MainMenuSheet:AddSheet( "Config", TabTwo, "icon16/key.png", false, false, "Administrative Configurations" )
// End of TabListName
end
--end

concommand.Add( "tdm_menu", tdm_menu )
usermessage.Hook( "MyMenu", tdm_menu )